package domain;

import java.net.Socket;

import android.content.Context;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;

import java.util.logging.*;
import AndroidHT.Workspace.AndroidHTActivity;

public class Gps implements LocationListener{
	
	public static String TAG = "Gps";
	
	public Telephone TelData;
	
	private double Latitud;
	private double Longitud;
	private float Velocidad;
	private double Altitud;
	
		
	AndroidHTActivity Activity;
	
	 public double GetLatitud()
	 {
		 return Latitud;
	 }
	 public double GetLongitud()
	 {
		 return Longitud;
	 }
	 public double GetAltitud()
	 {
		 return Altitud;
	 }
	 public float GetVelocidad()
	 {
		 return Velocidad;
	 }
	
	 public void onLocationChanged(Location location)
	 {
	  Latitud = location.getLatitude();
	  Longitud = location.getLongitude();
	  Velocidad = location.getSpeed();
	  Altitud = location.getAltitude();	  
	  
	 // Activity.updateCoordinates(this);
	  
	  try
	  {
		  
		  Log.i(TAG,"Enviando datos a Server");
		  Socket sock = new Socket("190.18.128.130",5123);
		 		  
		  String test = "{"
				  		+ "\"Id\":\""+"And"+"\","
				  		+ "\"Lat\":\""+this.Latitud+"\","
				  		+ "\"Lng\":\""+this.Longitud+"\","
				  		+ "\"Alt\":\""+this.Altitud+"\","
				  		+ "\"Spe\":\""+this.Velocidad+"\","						
				  		+ "\"IMEI\":\""+TelData.Imei+"\""
				  		+ "\"Mail\":\""+TelData.Email+"\""
		  				+ "}";
		  sock.getOutputStream().write(test.getBytes());
		  sock.close();
	  }
	  catch(Exception ex)
	  {
	      Log.e(TAG, "Error enviando al socket "+ex.getMessage());
	  }
	  
	  
	 }

	public void onProviderDisabled(String provider) 
	{
		
		
	}

	public void onProviderEnabled(String provider)
	{
	
		
	}

	public void onStatusChanged(String provider, int status, Bundle extras) {
		
		
	}
	public void loadActivity(AndroidHTActivity androidHTActivity) {
		
		Activity = androidHTActivity;
	}

}
